import axios from 'axios'
import config from './config'
import ENV from './apiList'
import parts from './parts'
// axios(config);
function API() {
  //获取已授权列表
  this.Boot = function (param, url, diyurl) {
    config.data.data = param.data;
    switch (ENV.APILIST[url]) {
      case undefined:
        // console.info('API name undefined ')
        break;
      case 'diy':
        return axios.post(diyurl, {}, config);
        break;
      default:
        return axios.post(ENV.APILIST[url], {}, config);
        break;
    }
  };
  this.getExcel = function (param) {
    return axios.get(ENV.HOST+ENV.APILIST[param.api]+param.url, config,{responseType: 'blob'})
  };
  this.Excel = function (param) {
    return axios.post(ENV.HOST+ENV.APILIST[param.api],param.data,{
      headers: {
        'Authorization': parts.GetStorage('asstoken'),
      },
    });
                                                                          //可选值为 arraybuffer,blob,document,json,text,stream，
  };
  this.post = function (param) {
    if (param.page) {
      config.params.page = param.page;
      return axios.post(ENV.APILIST[param.api], param.data, config);
    } else {
      config.params = {};
      return axios.post(ENV.APILIST[param.api], param.data, config);
    }
  };

  this.reqSuccess = function (obj, msg) {
    obj.$message({
      message: msg,
      fuck: 'feifei',
      type: 'success'
    });
  };
  this.reqFail = function (obj, msg) {
    obj.$message({
      message: msg,
      type: 'success'
    });
  };
  this.setHeader=function(e){
    config.headers.Authorization = e;
  }
}
export default API;
